package com.tsmti.system.entity;

import com.tsmti.core.util.ConvertUtil;
import com.tsmti.util.UserUtils;

import java.io.Serializable;

/**
 * Title：PimsSystem
 * Class：com.ts.sys.shiro.realm
 * Comapny:
 *
 * @author：zcw
 * @version：2.5 CreateTime：2018/1/17 14:36
 * Modify log:
 * Description：
 * 授权用户信息
 */
public  class Principal implements Serializable {
    private static final long serialVersionUID = 6850480534499601413L;
    /**
     * 编号
     */
    private Long id;
    /**
     * 登录名
     */
    private String username;
    /**
     * 姓名
     */
    private String realname;
    /**
     * 是否手机登录
     */
    private boolean mobileLogin;

    /**
     * 登陆机构ID
     */
    private String orgId;

    public Principal(User user, boolean mobileLogin,String orgId) {
        this.id = user.getId();
        this.username = user.getUserName();
        this.realname = user.getRealName();
        this.mobileLogin = mobileLogin;
        this.orgId = orgId;
    }

    public Long getId() {
        return id;
    }

    public String getUsername() {
        return username;
    }

    public String getRealname() {
        return realname;
    }

    public boolean isMobileLogin() {
        return mobileLogin;
    }
    public String getOrgId() {
        return orgId;
    }

    /**
     * 获取SESSIONID
     */
    public String getSessionid() {
        try {
            return (String) UserUtils.getSession().getId();
        } catch (Exception e) {
            return "";
        }
    }

    @Override
    public String toString() {
        return ConvertUtil.null2String(id);
    }

}
